#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    string destCity(vector<vector<string>>& paths) {
        map<std::string, int> search;
        int n = paths.size();
        for (int i = 0; i < n; i++)
        {
            if (--search[paths[i][0]] == 0) search.erase(paths[i][0]);
            if (++search[paths[i][1]] == 0) search.erase(paths[i][1]);
        }
        for (auto e : search)
        {
            if (e.second == 1) return e.first;
        }
        return string();
    }
};